<template>
  <view class="container">
    <!-- 顶部导航栏 -->
    <view class="top-bar">
      <view class="left-icon" @click="goBack"><text>&lt;</text></view>
      <view class="center-info">
        <image class="avatar" src="https://img1.imgtp.com/2023/06/01/12.jpg" />
        <view class="user-text">
          <text class="nickname">月亮金金子</text>
          <text class="status">当前在线</text>
        </view>
      </view>
      <view class="right-icon"></view>
    </view>

    <!-- 聊天内容区域 -->
    <scroll-view class="chat-content" scroll-y>
      <view v-for="(msg, index) in messages" :key="index" class="message-item" :class="{ 'self-message': msg.isSelf }">
        <image class="avatar" :src="msg.avatar" />
        <view class="message-bubble">
          <text>{{ msg.content }}</text>
        </view>
      </view>
    </scroll-view>

    <!-- 底部输入区域 -->
    <view class="bottom-bar">
      <view class="input-area">
        <view class="voice-icon"></view>
        <input class="message-input" placeholder="发消息..." />
        <view class="emoji-icon"></view>
        <view class="plus-icon"></view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: "ChatPage",
  data() {
    return {
      messages: [
        {
          avatar: 'https://img1.imgtp.com/2023/06/01/12.jpg',
          content: '你好！',
          isSelf: false
        },
        {
          avatar: 'https://img1.imgtp.com/2023/06/01/user_self.jpg', // 假设这是用户的头像
          content: '你好呀！',
          isSelf: true
        },
        {
          avatar: 'https://img1.imgtp.com/2023/06/01/12.jpg',
          content: '今天天气真好！',
          isSelf: false
        },
        {
          avatar: 'https://img1.imgtp.com/2023/06/01/user_self.jpg',
          content: '是呀，适合出去走走。',
          isSelf: true
        }
      ],
      quickReplies: ['棒', '笑哭了', '心心眼', '呢', '抽泣']
    };
  },
  methods: {
    goBack() {
      uni.navigateBack();
    }
  }
};
</script>

<style lang="less">
.container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background-color: #f6f6f6;
}

.top-bar {
  display: flex;
  align-items: center;
  padding: 20rpx 30rpx;
  background-color: #fff;
  border-bottom: 1rpx solid #eee;
}

.left-icon {
  font-size: 40rpx;
  color: #333;
  margin-right: 20rpx;
}

.center-info {
  display: flex;
  align-items: center;
  flex: 1;
}

.avatar {
  width: 80rpx;
  height: 80rpx;
  border-radius: 50%;
  margin-right: 20rpx;
}

.user-text {
  display: flex;
  flex-direction: column;
}

.nickname {
  font-size: 32rpx;
  font-weight: bold;
  color: #333;
}

.status {
  font-size: 24rpx;
  color: #888;
  margin-top: 4rpx;
}

.right-icon {
  width: 50rpx;
  text-align: right;
  /* 这里可以放更多图标 */
}

.chat-content {
  flex: 1;
  padding: 20rpx;
  overflow-y: scroll;
}

.message-item {
  display: flex;
  align-items: flex-start;
  margin-bottom: 30rpx;

  .avatar {
    width: 80rpx;
    height: 80rpx;
    border-radius: 50%;
    margin-right: 20rpx;
  }

  .message-bubble {
    background-color: #fff;
    padding: 20rpx 24rpx;
    border-radius: 16rpx;
    max-width: 70%;
    font-size: 28rpx;
    color: #333;
    word-break: break-all;
  }

  &.self-message {
    flex-direction: row-reverse;

    .avatar {
      margin-left: 20rpx;
      margin-right: 0;
    }

    .message-bubble {
      background-color: #d1f4d0; /* 更亮的绿色 */
    }
  }
}

.bottom-bar {
  padding: 20rpx;
  background-color: #fff;
  border-top: 1rpx solid #eee;
}

.input-area {
  display: flex;
  align-items: center;
}

.voice-icon,
.emoji-icon,
.plus-icon {
  width: 60rpx;
  height: 60rpx;
  background-color: #f0f0f0;
  border-radius: 50%;
  margin-right: 20rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40rpx;
  color: #888;
}

.message-input {
  flex: 1;
  height: 80rpx;
  background-color: #f0f0f0;
  border-radius: 40rpx;
  padding: 0 20rpx;
  font-size: 28rpx;
  margin-right: 20rpx;
}
</style> 